package cn.bdqn.config;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

public class UserRealm extends AuthorizingRealm {

    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        /*SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        String userName = (String) principalCollection.getPrimaryPrincipal();
        User user = userMapper.loadUserByUsername(userName);
        if (user != null){
            List<Role> userRoles = userMapper.getUserRolesByUid(user.getId());
            if (!CollectionUtils.isEmpty(userRoles)) {
                userRoles.forEach(role -> {
                    info.addRole(role.getName());
                });
            }
            return info;
        }*/
        return null;
    }

    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    /*    String userName = token.getPrincipal().toString();
        User user = userMapper.loadUserByUsername(userName);
        if (user == null){
            return null;
        }*/
//        return new SimpleAuthenticationInfo(user.getUsername(),user.getPassword(), ByteSource.Util.bytes(user.getUsername()),this.getName());
        return null;
    }
}
